package com.bsoft.gol.hcs.his.service.impl;

import com.bsoft.gol.hcs.clinical.bean.req.*;
import com.bsoft.gol.hcs.clinical.bean.req.inspectionreq.*;
import com.bsoft.gol.hcs.clinical.bean.response.*;
import com.bsoft.gol.hcs.clinical.bean.response.inspectionResq.*;
import com.bsoft.gol.hcs.clinical.bean.response.inspectionresponse.*;
import com.bsoft.gol.hcs.clinical.bean.vo.ConsultAskVo;
import com.bsoft.gol.hcs.clinical.clinicalEnum.ProcessCodeEnums;
import com.alibaba.fastjson.JSONObject;
import com.bsoft.gol.hcs.utils.*;
import ctd.util.xml.jaxb.JAXBUtils;
import com.bsoft.gol.hcs.enumcase.InspectionEmum;
import hcn.enums.PlatFormServiceEnum;
import hcn.util.BaseResponse;
import com.bsoft.gol.hcs.his.service.IInspectionHisXMLService;
import org.apache.http.client.utils.DateUtils;
import org.atag.sysrouter.context.RouteResult;
import org.atag.sysrouter.model.his.HisXmlHeader;
import org.atag.sysrouter.model.his.HisXmlRequest;
import org.atag.sysrouter.service.ServiceController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;
import service.rpc.DoctorInfoServiceIntf;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import static com.bsoft.gol.hcs.utils.WhisClientUtil.*;

/**
 * @Description: 检验his服务
 * @Author: zhaorb
 * @Date: 2020/6/4 15:08
 **/
@Service
public class InspectionHisXMLService implements IInspectionHisXMLService {
    private final static Logger log = LoggerFactory.getLogger(InspectionHisXMLService.class);

    @Value("${phis_path_url}")
    public String PHIS_PATH_URL;
    public static final String ORIGINORG = "1";

    @Value("${project_source}")
    private String proSource;

    @Autowired
    DoctorInfoServiceIntf doctorInfoRpcService;

    //入参转化
    public QueryInspectionItemListXmlNewReq transFormReq(QueryInspectionItemListReq req) {
        QueryInspectionItemListXmlNewReq xmlRequest = new QueryInspectionItemListXmlNewReq();
        QueryInspectionItemListNewReq queryInspectionItemListReq = new QueryInspectionItemListNewReq();
        queryInspectionItemListReq.setVisitOrganization(req.getOrganizationId());
        queryInspectionItemListReq.setRequestDept(req.getDepartmentId());
        queryInspectionItemListReq.setRequestDoctor(req.getDoctorId());
        queryInspectionItemListReq.setPatientType(req.getSource());
        queryInspectionItemListReq.setPinYinCode(req.getPinYinCode());
        xmlRequest.setRequest(queryInspectionItemListReq);
        return xmlRequest;
    }

    //出参转化
    public List<QueryInspectionItemListResp> transFormResqD0(List<QueryInspectionItemListNewResp> list) {
        List<QueryInspectionItemListResp> resps = new ArrayList<>();
        if (CommonUtils.isNotEmpty(list)) {
            for (QueryInspectionItemListNewResp resp : list) {
                QueryInspectionItemListResp queryInspectionItemListResp = new QueryInspectionItemListResp();
                queryInspectionItemListResp.setInspectionTypeId(resp.getItemTypeCode());
                queryInspectionItemListResp.setInspectionTypeName(resp.getItemTypeName());
                List<InspectionItemResp> inspectionItemResps = new ArrayList<>();
                if (CommonUtils.isNotEmpty(resp.getItems().getItem()) && resp.getItems().getItem().size() > 0) {
                    for (InspectionItemNewResp inspectionItemNewResp : resp.getItems().getItem()) {
                        InspectionItemResp inspectionItemResp = new InspectionItemResp();
                        inspectionItemResp.setInspectionTypeId(resp.getItemTypeCode());
                        inspectionItemResp.setInspectionTypeName(resp.getItemTypeName());
                        inspectionItemResp.setInspectionItemId(inspectionItemNewResp.getItemCode());
                        inspectionItemResp.setInspectionItemName(inspectionItemNewResp.getItemName());
                        inspectionItemResp.setIsCompose(inspectionItemNewResp.getComposeType());
                        inspectionItemResp.setIsEmergency(inspectionItemNewResp.getIsEmergency());
                        inspectionItemResp.setNumber(inspectionItemNewResp.getItemCount());
                        inspectionItemResp.setPrice(inspectionItemNewResp.getItemPrice());
                        inspectionItemResp.setPyCode(inspectionItemNewResp.getInputCode());
                        inspectionItemResp.setComposeAttribution(inspectionItemNewResp.getComposeAttribution());
                        inspectionItemResp.setSpecimenTypeId(inspectionItemNewResp.getSampleTypeCode());
                        inspectionItemResp.setSpecimenTypeName(inspectionItemNewResp.getSampleTypeName());
                        inspectionItemResps.add(inspectionItemResp);
                    }
                }
                queryInspectionItemListResp.setInspectionTypeList(inspectionItemResps);
                resps.add(queryInspectionItemListResp);
            }
        }
        return resps;
    }


    //入参转化
    public QueryInspectionItemDetailXmlNewReq transFormReq(QueryInspectionItemDtailReq req) {
        QueryInspectionItemDetailXmlNewReq xmlRequest = new QueryInspectionItemDetailXmlNewReq();
        QueryInspectionItemDtailNewReq queryInspectionItemListReq = new QueryInspectionItemDtailNewReq();
        queryInspectionItemListReq.setVisitOrganization(req.getOrganizationId());
        queryInspectionItemListReq.setItemCode(req.getInspectionItemId());
        xmlRequest.setRequest(queryInspectionItemListReq);
        return xmlRequest;
    }

    //出参转化
    public List<QueryInspectionItemDtailResp> transFormResqD1(List<QueryInspectionItemDtailNewResp> list) {
        List<QueryInspectionItemDtailResp> resps = new ArrayList<>();
        if (CommonUtils.isNotEmpty(list)) {
            for (QueryInspectionItemDtailNewResp resp : list) {
                QueryInspectionItemDtailResp queryInspectionItemListResp = new QueryInspectionItemDtailResp();
                queryInspectionItemListResp.setExecuteDepartmentId(resp.getExamExecuteDept());
                queryInspectionItemListResp.setExecuteDepartmentName(resp.getExamExecuteDeptName());
                queryInspectionItemListResp.setInspectionItemId(resp.getItemCode());
                queryInspectionItemListResp.setInspectionItemName(resp.getItemName());
                queryInspectionItemListResp.setNumber(resp.getItemCount());
                queryInspectionItemListResp.setPrice(resp.getItemPrice());
                List<ExpenseItemResp> inspectionItemResps = new ArrayList<>();
                if (CommonUtils.isNotEmpty(resp.getItemlists().getItemlist()) && resp.getItemlists().getItemlist().size() > 0) {
                    for (ExpenseItemNewResp inspectionItemNewResp : resp.getItemlists().getItemlist()) {
                        ExpenseItemResp expenseItemResp = new ExpenseItemResp();
                        expenseItemResp.setItemId(inspectionItemNewResp.getCostId());
                        expenseItemResp.setItemName(inspectionItemNewResp.getCostName());
                        expenseItemResp.setNumber(inspectionItemNewResp.getCostNumber());
                        expenseItemResp.setPrice(inspectionItemNewResp.getCostPrice());
                        expenseItemResp.setInspectionItemDetailId(inspectionItemNewResp.getChildItemCode());
                        expenseItemResp.setInspectionItemDetailName(inspectionItemNewResp.getChildItemName());
                        inspectionItemResps.add(expenseItemResp);
                    }
                }
                queryInspectionItemListResp.setItemList(inspectionItemResps);
                resps.add(queryInspectionItemListResp);
            }
        }
        return resps;
    }


    //入参转化
    public QueryInspectionItemDetailNewXmlReq transFormReq(QuerySampleTypeReq req) {
        QueryInspectionItemDetailNewXmlReq request = new QueryInspectionItemDetailNewXmlReq();
        QueryInspectionItemDtailNewReq queryInspectionItemListReq = new QueryInspectionItemDtailNewReq();
        queryInspectionItemListReq.setVisitOrganization(req.getOrganizationId());
        queryInspectionItemListReq.setItemCode(req.getInspectionItemId());
        request.setRequest(queryInspectionItemListReq);
        return request;
    }

    //出参转化
    public List<QuerySampleTypeResp> transFormResqD2(List<QuerySampleTypeNewResp> list) {
        List<QuerySampleTypeResp> resps = new ArrayList<>();
        if (CommonUtils.isNotEmpty(list)) {
            for (QuerySampleTypeNewResp resp : list) {
                QuerySampleTypeResp querySampleTypeResp = new QuerySampleTypeResp();
                querySampleTypeResp.setSpecimenTypeId(resp.getSampleTypeCode());
                querySampleTypeResp.setSpecimenTypeName(resp.getSampleTypeName());
                resps.add(querySampleTypeResp);
            }
        }
        return resps;
    }


    //入参转化
    public ApplyNoNewXmlRequest transFormReq(ApplyNoRequest req) {
        ApplyNoNewXmlRequest xmlRequest = new ApplyNoNewXmlRequest();
        ApplyNoNewRequest applyNoNewRequest = new ApplyNoNewRequest();
        applyNoNewRequest.setVisitOrganization(req.getOrganizationId());
        applyNoNewRequest.setRecordCount(req.getCount());
        xmlRequest.setRequest(applyNoNewRequest);
        return xmlRequest;
    }

    //出参转化
    public List<ApplyNoResponse> transFormResqD3(List<ApplyNoNewResponse> list) {
        List<ApplyNoResponse> resps = new ArrayList<>();
        if (CommonUtils.isNotEmpty(list)) {
            for (ApplyNoNewResponse resp : list) {
                ApplyNoResponse querySampleTypeResp = new ApplyNoResponse();
                querySampleTypeResp.setApplicationNo(resp.getRequestId());
                resps.add(querySampleTypeResp);
            }
        }
        return resps;
    }


    //入参转化
    public SaveInspectionInfoNewReq transFormReq(SaveInspectionInfoReq req, ConsultAskVo consultAsk) {
        SaveInspectionInfoNewReq saveInspectionInfoNewReq = new SaveInspectionInfoNewReq();
        //患者信息
        PatientHis patient = new PatientHis();
        patient.setSourcePatientId(req.getPatientId());
        patient.setSourcePatientIdType("OV");//todo
        patient.setAuthorOrganization(req.getOrganizationId());//todo
        patient.setIdCard(req.getCardNumber());
        patient.setIdCardCode(req.getCardType());
        patient.setName(req.getPatientName());
        patient.setSex(req.getSex());
        patient.setSexName(null == req.getSexName() ? "" : req.getSexName());
        patient.setBirthDate(null == req.getBirthday() ? "" : req.getBirthday());
        patient.setPatientPhone(req.getTelephone());
        patient.setAddress(null == req.getAddress() ? "" : req.getAddress());
        patient.setPatientProperties("1000");
        patient.setSourceVisitId(consultAsk.getEmergencyNumber());
        patient.setClinicId(consultAsk.getPatientMedicalCardNumber());
        patient.setHospizationId("");
        saveInspectionInfoNewReq.setPatient(patient);

        //就诊摘要
        Visit visit = new Visit();
        visit.setVisitId(consultAsk.getEmergencyNumber());
        visit.setVisitOrganization(req.getOrganizationId());
        visit.setPatientType(req.getSource());
        visit.setPatientTypeName("");
        visit.setMedicalCardId(req.getPatientMedicalCardNumber());
        visit.setMedicalCardType(req.getPatientMedicalCardType());
        visit.setClinicId("");
        visit.setHospizationId("");
//        visit.setPatientProperties(req.getPatientProperties());
        visit.setPatientPhone("");
        visit.setAddress("");
        saveInspectionInfoNewReq.setVisit(visit);
        //申请单

        ExamineDetailReq examineDetailReq = req.getApplicationlist();
        LabRequest labRequest = new LabRequest();
        labRequest.setRequestId(examineDetailReq.getApplicationNo());
        labRequest.setIsNeonatus(examineDetailReq.getIsNeonatus());//todo
        labRequest.setAge(String.valueOf(examineDetailReq.getAge()));//todo
        labRequest.setMonthAge("");
        labRequest.setWardArea("");
        labRequest.setWardAreaName("");
        labRequest.setSickbedId("");
        labRequest.setSickRoomId("");
        labRequest.setSickRoomNo("");
        labRequest.setSickbedNo("");
        labRequest.setIsEmergency(examineDetailReq.getIsEmergency());
        labRequest.setRequestModeName("");
        labRequest.setRequestDateTime(DateUtil.format5.format(new Date()));
        labRequest.setEffectiveTimeLow(null == examineDetailReq.getEffectiveTimeLow() ? "" : examineDetailReq.getEffectiveTimeLow());//todo
        labRequest.setEffectiveTimeHigh(null == examineDetailReq.getEffectiveTimeHigh() ? "" : examineDetailReq.getEffectiveTimeHigh());//todo
        labRequest.setRequestDoctor(examineDetailReq.getApplyDoctorId());
        labRequest.setRequestDoctorName(examineDetailReq.getApplyDoctorName());
        labRequest.setRequestDept(examineDetailReq.getApplyDepartmentId());
        labRequest.setRequestDeptName(examineDetailReq.getApplyDepartmentName());
        labRequest.setRequestCheckerId(null == examineDetailReq.getRequestCheckerId() ? "" : examineDetailReq.getRequestCheckerId());//todo
        labRequest.setRequestCheckerName(null == examineDetailReq.getRequestCheckerName() ? "" : examineDetailReq.getRequestCheckerName());//todo
        labRequest.setRequestCheckTime(null == examineDetailReq.getRequestCheckTime() ? "" : examineDetailReq.getRequestCheckTime());//todo
        labRequest.setExamText("");
        labRequest.setExamExecuteOrg("");
        labRequest.setRequestStatus(2);//todo
        labRequest.setDept(null == examineDetailReq.getDepartmentId() ? "" : examineDetailReq.getDepartmentId());
        labRequest.setDeptName(null == examineDetailReq.getDepartmentName() ? "" : examineDetailReq.getDepartmentName());
        labRequest.setRemarkInfo("");
        //诊断
        List<Diagnose> diagnoses = new ArrayList<>();
        List<DiagnosisReq> diagnosisReqs = examineDetailReq.getDiagnosisReqList();
        if (CommonUtils.isNotEmpty(diagnosisReqs)) {
            for (DiagnosisReq diagnosisReq : diagnosisReqs) {
                Diagnose diagnose = new Diagnose();
                diagnose.setDiagnoseTypeCode(diagnosisReq.getDiagnosisType());
                diagnose.setDiagnoseTypeName(diagnosisReq.getDiseasesName());
                diagnose.setDiagnoseCode(diagnosisReq.getDiseasesId());
                diagnose.setDiagnoseName("");
                diagnose.setDiagnoseDateTime("");
                diagnoses.add(diagnose);
            }
        }

        LabRequest.Diagnoses diagnoses1 = new LabRequest.Diagnoses();
        diagnoses1.setDiagnose(diagnoses);
        labRequest.setDiagnoses(diagnoses1);

        //检验申请项目
        List<Item> items = new ArrayList<>();
        List<InspectionItemDetail> inspectionItemDetails = examineDetailReq.getInspectionItemDetailList();
        if (CommonUtils.isNotEmpty(inspectionItemDetails)) {
            for (InspectionItemDetail itemDetail : inspectionItemDetails) {
                Item item = new Item();
                item.setOrderId("1");
//                item.setOrderId(null == itemDetail.getExpenseId()?"":itemDetail.getExpenseId());
                item.setBarcodeNo(null == itemDetail.getBarcodeNo() ? "" : itemDetail.getBarcodeNo());
                item.setItemCode(null == itemDetail.getInspectionItemId() ? "" : itemDetail.getInspectionItemId());
                item.setItemName(null == itemDetail.getInspectionItemName() ? "" : itemDetail.getInspectionItemName());
                item.setSampleTypeCode(null == itemDetail.getSpecimenTypeId() ? "" : itemDetail.getSpecimenTypeId());
                item.setSampleTypeName(null == itemDetail.getSpecimenTypeName() ? "" : itemDetail.getSpecimenTypeName());
                item.setItemPrice(itemDetail.getPrice());
                item.setItemCount(itemDetail.getNumber());
                item.setItemCost(itemDetail.getItemCost());
                item.setFeeStatus(itemDetail.getFeeStatus());//todo
                item.setCostFreeSign("0");
                item.setExamExecuteDept(null == itemDetail.getExecuteDepartmentId() ? "" : itemDetail.getExecuteDepartmentId());
                item.setExamExecuteDeptName(null == itemDetail.getExecuteDepartmentName() ? "" : itemDetail.getExecuteDepartmentName());
                item.setExamExecuteTime("");
                item.setRequestNote("");
                item.setInvoiceNo("");
                item.setExamMethodCode("");
                item.setExamMethodName("");
                item.setFeetype(itemDetail.getFeeType());

                List<Childitem> childitems = new ArrayList<>();
                if (CommonUtils.isNotEmpty(itemDetail.getItemList())) {
                    for (ItemDetail detail : itemDetail.getItemList()) {
                        Childitem childitem = new Childitem();
                        childitem.setChildItemCode(null == detail.getInspectionItemDetailId() ? "" : detail.getInspectionItemDetailId());
                        childitem.setChildItemName(null == detail.getInspectionItemDetailName() ? "" : detail.getInspectionItemDetailName());
                        childitem.setOrderDetailId(null == detail.getJlxh() ? "" : detail.getJlxh());
                        childitem.setOrderDetailId("2");
                        childitem.setCostId(detail.getItemId());
                        childitem.setCostName(detail.getItemName());
                        childitem.setCostPrice(detail.getPrice());
                        childitem.setCostNumber(detail.getNumber());
                        childitems.add(childitem);
                    }
                }

                Item.Childitems citems = new Item.Childitems();
                citems.setChilditem(childitems);
                item.setChilditems(citems);
                items.add(item);
            }
        }

        LabRequest.Items items1 = new LabRequest.Items();
        items1.setItem(items);
        labRequest.setItems(items1);
        saveInspectionInfoNewReq.setLabRequest(labRequest);

        List<BaseHisPlateformClpInfoXmlRequest> clpInfos = new ArrayList<>();
        BaseHisPlateformClpInfoXmlRequest clpInfoXmlRequest = new BaseHisPlateformClpInfoXmlRequest();
        clpInfoXmlRequest.setBusinessID(examineDetailReq.getApplicationNo());
        clpInfoXmlRequest.setBusinessCircleID("");
        clpInfoXmlRequest.setBusinessCompsiteID("");
        clpInfoXmlRequest.setFlowCode(ProcessCodeEnums.SUBMIT_LAB_ORDER.getProcessCode());
        clpInfoXmlRequest.setFlowName(ProcessCodeEnums.SUBMIT_LAB_ORDER.getProcessName());
        clpInfoXmlRequest.setOperateTypeCode(ProcessCodeEnums.SUBMIT_LAB_ORDER.getInterfaceCode());
        clpInfoXmlRequest.setOperateTypeName(ProcessCodeEnums.SUBMIT_LAB_ORDER.getInterfaceName());
        clpInfoXmlRequest.setOperatorCode(consultAsk.getDoctorCode());
        clpInfoXmlRequest.setOperatorName(consultAsk.getDoctorName());
        clpInfoXmlRequest.setOperateDeptCode(consultAsk.getLocalDeptId());
        clpInfoXmlRequest.setOperateDeptName(consultAsk.getDepartmentName());
        String dateTime = DateUtils.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss")
                .replace("-", "").replace(":", "")
                .replace(" ", "T");
        clpInfoXmlRequest.setOperateDateTime(dateTime);
        clpInfoXmlRequest.setGroupId("");
        clpInfoXmlRequest.setGroupName("");
        clpInfoXmlRequest.setOperateComments("");

        clpInfos.add(clpInfoXmlRequest);

        saveInspectionInfoNewReq.setClpInfos(clpInfos);


        return saveInspectionInfoNewReq;
    }

    //出参转化
    public SaveInspectionInfoResp transFormResqD4(SaveInspectionInfoNewResp newResp) {
        SaveInspectionInfoResp resps = new SaveInspectionInfoResp();
        if (CommonUtils.isNotEmpty(newResp)) {
            resps.setOrganizationId(newResp.getVisitOrganization());
            resps.setOrganizationName(newResp.getVisitOrganizationName());
            resps.setPatientId(newResp.getSourcePatientId());
            resps.setPatientName(newResp.getName());
            resps.setSex(newResp.getSex());
            resps.setCardType(newResp.getIdCardCode());
            resps.setCardNumber(newResp.getIdCard());
            resps.setPatientMedicalCardType(newResp.getMedicalCardType());
            resps.setPatientMedicalCardNumber(newResp.getMedicalCardId());
            resps.setEmergencyNumber(newResp.getVisitId());
            resps.setDepartmentId(newResp.getDept());
            resps.setDepartmentName(newResp.getDeptName());
            resps.setApplyDoctorId(newResp.getRequestDoctor());
            resps.setApplyDoctorName(newResp.getRequestDoctorName());
            resps.setApplyDepartmentId(newResp.getRequestDept());
            resps.setApplyDepartmentName(newResp.getRequestDeptName());
            ExpenseLabReq expenseLabReq = new ExpenseLabReq();
            ExpenseItemNewReq itemNewReq = newResp.getLabRequest();
            if (CommonUtils.isNotEmpty(itemNewReq)) {
                expenseLabReq.setApplicationNo(itemNewReq.getRequestId());
                if ("2".equals(itemNewReq.getRequestStatus())) {
                    expenseLabReq.setApplyStatus("1");
                } else {
                    expenseLabReq.setApplyStatus(itemNewReq.getRequestStatus());
                }
                expenseLabReq.setEmergencyTag(itemNewReq.getIsEmergency());

                List<Item> list = itemNewReq.getItems().getItem();
                List<ExpenseItemReq> expenseItemReqs = new ArrayList<>();
                if (CommonUtils.isNotEmpty(list)) {
                    for (Item item : list) {
                        ExpenseItemReq expenseItemReq = new ExpenseItemReq();
                        expenseItemReq.setExpenseId(item.getAdviceExpenseId());
                        expenseItemReq.setExpenseIdSource(item.getOrderId());
                        expenseItemReq.setInspectionItemId(item.getItemCode());
                        expenseItemReq.setInspectionItemName(item.getItemName());
                        expenseItemReq.setSpecimenTypeId(item.getSampleTypeCode());
                        expenseItemReq.setSpecimenTypeName(item.getSampleTypeName());
                        expenseItemReq.setTotalAmount(item.getItemCost());
                        expenseItemReq.setChargeStatus(item.getFeeStatus());
                        expenseItemReq.setFeeType(item.getFeetype());

                        List<ExpenseDetailReq> expenseDetailReqs = new ArrayList<>();
                        List<Childitem> childitems = item.getChilditems().getChilditem();
                        if (CommonUtils.isNotEmpty(childitems)) {
                            for (Childitem childitem : childitems) {
                                ExpenseDetailReq expenseDetailReq = new ExpenseDetailReq();
                                expenseDetailReq.setInspectionItemDetailId(childitem.getChildItemCode());
                                expenseDetailReq.setInspectionItemDetailName(childitem.getChildItemName());
                                expenseDetailReq.setExpenseDetailId(childitem.getAdviceExpenseDetailId());
                                expenseDetailReq.setItemId(childitem.getCostId());
                                expenseDetailReq.setItemName(childitem.getCostName());
                                expenseDetailReq.setNumber(childitem.getCostNumber());
                                expenseDetailReq.setPrice(childitem.getCostPrice());
                                expenseDetailReq.setUnit(childitem.getCostUnit());
                                expenseDetailReq.setAmount(childitem.getDetailCost());
                                expenseDetailReqs.add(expenseDetailReq);
                            }
                        }
                        expenseItemReq.setDetailList(expenseDetailReqs);
                        expenseItemReqs.add(expenseItemReq);
                    }

                }
                expenseLabReq.setItemReqList(expenseItemReqs);
            }

            resps.setList(expenseLabReq);
        }
        return resps;
    }


    //入参转化
    public CancelInspectionItemXmlNewReq transFormReq(CancelInspectionItemReq req) {
        CancelInspectionItemXmlNewReq xmlRequest = new CancelInspectionItemXmlNewReq();
        CancelInspectionItemNewReq cancelInspectionItemNewReq = new CancelInspectionItemNewReq();
        cancelInspectionItemNewReq.setVisitOrganization(req.getOrganizationId());
        cancelInspectionItemNewReq.setConsultId(req.getConsultId());
        cancelInspectionItemNewReq.setOperatorId(req.getOperatorId());
        cancelInspectionItemNewReq.setOperatorName(req.getOperatorName());
        cancelInspectionItemNewReq.setRegisteredSerialNo(req.getRegisteredSerialNo());
        cancelInspectionItemNewReq.setRequestId(req.getApplicationNo());
        cancelInspectionItemNewReq.setOperateDateTime(req.getOperationTime());
        xmlRequest.setRequest(cancelInspectionItemNewReq);
        return xmlRequest;
    }


    //入参转化
    public QueryInspectionExtraFeeXmlNewReq transFormReq(QueryInspectionExtraFeeReq req) {
        QueryInspectionExtraFeeXmlNewReq xmlRequest = new QueryInspectionExtraFeeXmlNewReq();
        QueryInspectionExtraFeeNewReq inspectionExtraFeeNewReq = new QueryInspectionExtraFeeNewReq();
        inspectionExtraFeeNewReq.setVisitOrganization(req.getOrganizationId());
        List<InspectionItemNew> Itemlists = new ArrayList<>();
        if (CommonUtils.isNotEmpty(req.getInspectionItemList())) {
            for (InspectionItem inspectionItem : req.getInspectionItemList()) {
                InspectionItemNew inspectionItemNew = new InspectionItemNew();
                inspectionItemNew.setItemCode(inspectionItem.getInspectionItemId());
                inspectionItemNew.setItemName(inspectionItem.getInspectionItemName());
                inspectionItemNew.setRequestId(inspectionItem.getApplicationNo());
                inspectionItemNew.setSampleTypeCode(inspectionItem.getSpecimenTypeId());
                inspectionItemNew.setSampleTypeName(inspectionItem.getSpecimenTypeName());
                inspectionItemNew.setItemCount(inspectionItem.getNumber());
                Itemlists.add(inspectionItemNew);
            }
        }
        QueryInspectionExtraFeeNewReq.Itemlists itemlistsS = new QueryInspectionExtraFeeNewReq.Itemlists();
        itemlistsS.setItemlist(Itemlists);
        inspectionExtraFeeNewReq.setItemlists(itemlistsS);
        xmlRequest.setRequest(inspectionExtraFeeNewReq);
        return xmlRequest;
    }

    //出参转化
    public QueryInspectionExtraFeeResp transFormResqD6(QueryInspectionExtraFeeNewResp list) {
        QueryInspectionExtraFeeResp resps = new QueryInspectionExtraFeeResp();
        List<ExtraFee> extraFees = new ArrayList<>();
        if (CommonUtils.isNotEmpty(list.getItemlist())) {
            for (ExtraFeeNew resp : list.getItemlist()) {
                ExtraFee extraFee = new ExtraFee();
                extraFee.setApplicationNo(resp.getRequestId());
                extraFee.setExecuteDepartmentId(resp.getExamExecuteDept());
                extraFee.setItemId(resp.getCostId());
                extraFee.setItemName(resp.getCostName());
                extraFee.setNumber(resp.getCostNumber());
                extraFee.setPrice(resp.getCostPrice());
                extraFees.add(extraFee);
            }
        }

        resps.setItemList(extraFees);
        return resps;
    }


    //入参转化
    public QueryInspectionExtraFeeXmlNewReq transFormReq(QueryInspectionNoticeReq req) {
        QueryInspectionExtraFeeXmlNewReq xmlRequest = new QueryInspectionExtraFeeXmlNewReq();
        QueryInspectionExtraFeeNewReq inspectionExtraFeeNewReq = new QueryInspectionExtraFeeNewReq();
        inspectionExtraFeeNewReq.setVisitOrganization(req.getOrganizationId());
        List<InspectionItemNew> Itemlists = new ArrayList<>();
        if (CommonUtils.isNotEmpty(req.getInspectionItemList())) {
            for (InspectionItem inspectionItem : req.getInspectionItemList()) {
                InspectionItemNew inspectionItemNew = new InspectionItemNew();
                inspectionItemNew.setItemCode(inspectionItem.getInspectionItemId());
                inspectionItemNew.setItemName(inspectionItem.getInspectionItemName());
                inspectionItemNew.setRequestId(inspectionItem.getApplicationNo());
                inspectionItemNew.setSampleTypeCode(inspectionItem.getSpecimenTypeId());
                inspectionItemNew.setSampleTypeName(inspectionItem.getSpecimenTypeName());
                inspectionItemNew.setItemCount(inspectionItem.getNumber());
                Itemlists.add(inspectionItemNew);
            }
        }
        QueryInspectionExtraFeeNewReq.Itemlists itemlists = new QueryInspectionExtraFeeNewReq.Itemlists();
        itemlists.setItemlist(Itemlists);
        inspectionExtraFeeNewReq.setItemlists(itemlists);
        xmlRequest.setRequest(inspectionExtraFeeNewReq);
        return xmlRequest;
    }


    //出参转化
    public List<QueryInspectionNoticeResp> transFormResqD7(List<QueryInspectionNoticeNewResp> list) {
        List<QueryInspectionNoticeResp> resps = new ArrayList<>();
        if (CommonUtils.isNotEmpty(list)) {
            for (QueryInspectionNoticeNewResp resp : list) {
                QueryInspectionNoticeResp querySampleTypeResp = new QueryInspectionNoticeResp();
                querySampleTypeResp.setInspectionItems(resp.getExaminationPurpose());
                querySampleTypeResp.setSamplingAttention(resp.getRequestNote());
                querySampleTypeResp.setSamplingPlace(resp.getSampleCollectPlace());
                resps.add(querySampleTypeResp);
            }
        }
        return resps;
    }


    /**
     * 检验申请单信息查询
     *
     * @param request
     * @return
     */
    @Override
    public BaseResponse<LabQueryResp> queryILabRequestQueryXML(LabRequestQueryRequest request) {
        log.info("queryInspectionItemList-入参=>>>" + request.toString() + "=====");
        String serviceName = PlatFormServiceEnum.LabRequestQuery.getServiceName();
        String msgType = PlatFormServiceEnum.LabRequestQuery.getServiceCode();
        BaseResponse baseResponse = new BaseResponse();
        try {
            HisXmlRequest<LabRequestQueryRequest> req = new HisXmlRequest<>();
            req.setHeader(HisXmlHeader.Builder.custom()
                    .organization(request.getPatient().getAuthorOrganization())
                    .sender("GOL")
                    .serviceType(Constants.SERVICE_TYPE_SERVICE)
                    .msgType(msgType)
                    .build());
            req.setBody(request);
            LabQueryResp data = ServiceController.instance().singleWork(serviceName, request.getPatient().getAuthorOrganization(), req, LabQueryResp.class);
            if (CommonUtils.isNotEmpty(data)) {
                baseResponse.setData(data);
            } else {
                baseResponse = BaseRespUtil.setResultError("检验申请单信息查询失败");
            }
        } catch (Exception e) {
            baseResponse = BaseRespUtil.setResultError("请求" + serviceName + "接口异常");
            return baseResponse;
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        return baseResponse;
    }


    /**
     * 获取检验申请单类别和项目
     *
     * @param request
     * @return
     */
    @Override
    public BaseResponse<List<QueryInspectionItemListResp>> queryInspectionItemListXML(QueryInspectionItemListReq request) {
        log.info("queryInspectionItemList-入参=>>>" + request.toString() + "=====");
        String serviceName = PlatFormServiceEnum.LabRequestQueryItems.getServiceName();
        String msgType = PlatFormServiceEnum.LabRequestQueryItems.getServiceCode();
        BaseResponse baseResponse = new BaseResponse();
        List<QueryInspectionItemListNewResp> resps = new ArrayList<>();
        QueryInspectionItemListXmlNewReq xmlRequest = this.transFormReq(request);
        try {
            HisXmlRequest<QueryInspectionItemListXmlNewReq> req = new HisXmlRequest<>();
            req.setHeader(HisXmlHeader.Builder.custom()
                    .organization(request.getOrganizationId())
                    .sender("GOL")
                    .serviceType(Constants.SERVICE_TYPE_SERVICE)
                    .msgType(msgType)
                    .build());
            req.setBody(xmlRequest);
            LabRequestQueryItemsResponse.MsgBody.Data data = ServiceController.instance().singleWork(serviceName, request.getOrganizationId(), req, LabRequestQueryItemsResponse.MsgBody.Data.class);
            if (CommonUtils.isNotEmpty(data) && CommonUtils.isNotEmpty(data.getDatalists())) {
                resps = data.getDatalists().getDatalist();
                List<QueryInspectionItemListResp> list = this.transFormResqD0(resps);
                baseResponse.setData(list);
            } else {
                baseResponse = BaseRespUtil.setResultError("获取检验申请单类别和项目失败");
            }
        } catch (Exception e) {
            baseResponse = BaseRespUtil.setResultError("请求" + serviceName + "接口异常");
            return baseResponse;
        }
        return baseResponse;
    }

    /**
     * 获取检验申请单子项目明细
     *
     * @param request
     * @return
     */
    @Override
    public BaseResponse<List<QueryInspectionItemDtailResp>> queryInspectionItemDtailXML(QueryInspectionItemDtailReq request) {
        log.info("queryInspectionItemDtail-入参=>>>" + request.toString() + "=====");
        String serviceName = PlatFormServiceEnum.LabRequestQueryItemDtail.getServiceName();
        String msgType = PlatFormServiceEnum.LabRequestQueryItemDtail.getServiceCode();
        BaseResponse baseResponse = new BaseResponse();
        QueryInspectionItemDetailXmlNewReq xmlRequest = this.transFormReq(request);
        List<QueryInspectionItemDtailNewResp> resps = new ArrayList<>();
        try {
            HisXmlRequest<QueryInspectionItemDetailXmlNewReq> req = new HisXmlRequest<>();
            req.setHeader(HisXmlHeader.Builder.custom()
                    .organization(request.getOrganizationId())
                    .sender("GOL")
                    .serviceType(Constants.SERVICE_TYPE_SERVICE)
                    .msgType(msgType)
                    .build());
            req.setBody(xmlRequest);
            LabRequestQueryItemDtailResponse.MsgBody.Data data = ServiceController.instance().singleWork(serviceName, request.getOrganizationId(), req, LabRequestQueryItemDtailResponse.MsgBody.Data.class);
            if (CommonUtils.isNotEmpty(data) && CommonUtils.isNotEmpty(data.getItems())) {
                resps = data.getItems().getItem();
                List<QueryInspectionItemDtailResp> list = this.transFormResqD1(resps);
                baseResponse.setData(list);
            } else {
                baseResponse = BaseRespUtil.setResultError("获取检验申请单子项目明细失败");
            }
        } catch (Exception e) {
            baseResponse = BaseRespUtil.setResultError("请求" + serviceName + "接口异常");
            return baseResponse;
        }
        return baseResponse;
    }

    /**
     * 3、获取样本类型
     *
     * @param request
     * @return
     */
    @Override
    public BaseResponse<List<QuerySampleTypeResp>> querySampleTypeXML(QuerySampleTypeReq request) {
        log.info("querySampleType-入参=>>>" + request.toString() + "=====");
        BaseResponse baseResponse = new BaseResponse();
        List<QuerySampleTypeNewResp> resps = new ArrayList<>();
        String serviceName = PlatFormServiceEnum.LabRequestQuerySampletype.getServiceName();
        String msgType = PlatFormServiceEnum.LabRequestQuerySampletype.getServiceCode();
        QueryInspectionItemDetailNewXmlReq inspectionItemRequest = this.transFormReq(request);
        try {
            HisXmlRequest<QueryInspectionItemDetailNewXmlReq> req = new HisXmlRequest<>();
            req.setHeader(HisXmlHeader.Builder.custom()
                    .organization(request.getOrganizationId())
                    .sender("GOL")
                    .serviceType(Constants.SERVICE_TYPE_SERVICE)
                    .msgType(msgType)
                    .build());
            req.setBody(inspectionItemRequest);
            SampleTypeNewResponse.MsgBody.Data data = ServiceController.instance().singleWork(serviceName, request.getOrganizationId(), req, SampleTypeNewResponse.MsgBody.Data.class);
            if (CommonUtils.isNotEmpty(data) && CommonUtils.isNotEmpty(data.getDatalists())) {
                resps = data.getDatalists().getDatalist();
                List<QuerySampleTypeResp> querySampleTypeResps = this.transFormResqD2(resps);
                baseResponse.setData(querySampleTypeResps);
            }
        } catch (Exception e) {
            baseResponse = BaseRespUtil.setResultError("请求" + serviceName + "接口异常");
            return baseResponse;
        }
        return baseResponse;
    }


    /**
     * @Description: 获得检验申请单号
     * @Author: zhaorb
     * @Date: 2020/8/4 14:05
     **/
    @Override
    public BaseResponse<List<ApplyNoResponse>> queryInspectionApplyNoXML(ApplyNoRequest request) {
        BaseResponse baseResponse = new BaseResponse();
        List<ApplyNoNewResponse> resp = new ArrayList<>();
        String serviceName = PlatFormServiceEnum.LabRequestGetRequestId.getServiceName();
        String msgType = PlatFormServiceEnum.LabRequestGetRequestId.getServiceCode();
        ApplyNoNewXmlRequest applyNoNewXmlRequest = this.transFormReq(request);
        try {
            HisXmlRequest<ApplyNoNewXmlRequest> req = new HisXmlRequest<>();
            req.setHeader(HisXmlHeader.Builder.custom()
                    .organization(request.getOrganizationId())
                    .sender("GOL")
                    .serviceType(Constants.SERVICE_TYPE_SERVICE)
                    .msgType(msgType)
                    .build());
            req.setBody(applyNoNewXmlRequest);
            LabRequestGetRequestIdResponse.MsgBody.Data data = ServiceController.instance().singleWork(serviceName, request.getOrganizationId(), req, LabRequestGetRequestIdResponse.MsgBody.Data.class);
            if (CommonUtils.isNotEmpty(data) && CommonUtils.isNotEmpty(data.getDatalists())) {
                resp = data.getDatalists().getDatalist();
                List<ApplyNoResponse> responses = this.transFormResqD3(resp);
                baseResponse.setData(responses);
            }
        } catch (Exception e) {
            baseResponse = BaseRespUtil.setResultError("请求" + serviceName + "接口异常");
            return baseResponse;
        }
        return baseResponse;
    }

    /**
     * 提交申请单
     *
     * @param saveInspectionInfoReq
     * @return
     */
    @Override
    public BaseResponse<SaveInspectionInfoResp> saveInspectionInfoXML(SaveInspectionInfoReq saveInspectionInfoReq, ConsultAskVo consultAsk) {
        BaseResponse baseResponse = new BaseResponse();
        String serviceName = PlatFormServiceEnum.LabRequestSubmit.getServiceName();
        String msgType = PlatFormServiceEnum.LabRequestSubmit.getServiceCode();
        SaveInspectionInfoNewReq saveInspectionInfoNewReq = this.transFormReq(saveInspectionInfoReq, consultAsk);
        try {
            HisXmlRequest<SaveInspectionInfoNewReq> req = new HisXmlRequest<>();
            req.setHeader(HisXmlHeader.Builder.custom()
                    .organization(saveInspectionInfoReq.getOrganizationId())
                    .sender("GOL")
                    .serviceType(Constants.SERVICE_TYPE_SERVICE)
                    .msgType(msgType)
                    .build());
            req.setBody(saveInspectionInfoNewReq);
            SaveInspectionInfoNewResp data = ServiceController.instance().singleWork(serviceName, saveInspectionInfoReq.getOrganizationId(), req, SaveInspectionInfoNewResp.class);
            if (CommonUtils.isNotEmpty(data)) {
                SaveInspectionInfoResp saveInspectionInfoResp = this.transFormResqD4(data);
                baseResponse.setData(saveInspectionInfoResp);
            }
        } catch (Exception e) {
            log.error(e.getMessage());
            baseResponse = BaseRespUtil.setResultError(ExceptionMessageUtil.operateHisErrorMessage(e.getMessage()));
            return baseResponse;
        }

        return baseResponse;
    }

    /**
     * 7、撤销申请单
     *
     * @param request
     * @return
     */
    @Override
    public BaseResponse cancelInspectionItemXML(CancelInspectionItemReq request) {
        log.info("=cancelInspectionItem-入参=>>>" + request.toString() + "=====");
        String serviceName = PlatFormServiceEnum.LabRequestCancel.getServiceName();
        String msgType = PlatFormServiceEnum.LabRequestCancel.getServiceName();
        BaseResponse baseResponse = new BaseResponse();
        CancelInspectionItemXmlNewReq cancelInspectionItemNewReq = this.transFormReq(request);
        try {
            HisXmlRequest<CancelInspectionItemXmlNewReq> req = new HisXmlRequest<>();
            req.setHeader(HisXmlHeader.Builder.custom()
                    .organization(request.getOrganizationId())
                    .sender("GOL")
                    .serviceType(Constants.SERVICE_TYPE_SERVICE)
                    .msgType(msgType)
                    .build());
            req.setBody(cancelInspectionItemNewReq);
            RouteResult routeResult = ServiceController.instance().rawSingleWork(serviceName, request.getOrganizationId(), req, Object.class);
            if (routeResult.getSuccess()) {//返回成功
                baseResponse.setMessage(routeResult.getDetail());
            } else {
                baseResponse = BaseRespUtil.setResultError(routeResult.getDetail());
            }
        } catch (Exception e) {
            baseResponse = BaseRespUtil.setResultError("请求" + serviceName + "接口异常");
            return baseResponse;
        }
        return baseResponse;
    }

    /**
     * 5、获取申请单项目附加费用
     *
     * @param request
     * @return
     */
    @Override
    public BaseResponse<QueryInspectionExtraFeeResp> queryInspectionExtraFeeXML(QueryInspectionExtraFeeReq request) {
        log.info("=queryInspectionExtraFee-入参=>>>" + request.toString() + "=====");
        BaseResponse<QueryInspectionExtraFeeResp> baseResponse = new BaseResponse();
        String serviceName = PlatFormServiceEnum.LabRequestGetSurcharge.getServiceName();
        String msgType = PlatFormServiceEnum.LabRequestGetSurcharge.getServiceCode();
        QueryInspectionExtraFeeNewResp resp = new QueryInspectionExtraFeeNewResp();
        QueryInspectionExtraFeeXmlNewReq inspectionExtraFeeRequest = this.transFormReq(request);
        try {
            HisXmlRequest<QueryInspectionExtraFeeXmlNewReq> req = new HisXmlRequest<>();
            req.setHeader(HisXmlHeader.Builder.custom()
                    .organization(request.getOrganizationId())
                    .sender("GOL")
                    .serviceType(Constants.SERVICE_TYPE_SERVICE)
                    .msgType(msgType)
                    .build());
            req.setBody(inspectionExtraFeeRequest);
            LabRequestGetSurchargeResponse.MsgBody.Data data = ServiceController.instance().singleWork(serviceName, request.getOrganizationId(), req, LabRequestGetSurchargeResponse.MsgBody.Data.class);
            if (CommonUtils.isNotEmpty(data) && CommonUtils.isNotEmpty(data.getItemlists())) {
                resp = data.getItemlists();
                QueryInspectionExtraFeeResp resps = this.transFormResqD6(resp);
                baseResponse.setData(resps);
            } else {
                baseResponse = BaseRespUtil.setResultError("获取申请单项目附加费用失败");
            }
        } catch (Exception e) {
            baseResponse = BaseRespUtil.setResultError("请求" + serviceName + "接口异常");
            return baseResponse;
        }
        return baseResponse;
    }

    /**
     * 6、获取申请单注意事项
     *
     * @param request
     * @return
     */
    @Override
    public BaseResponse<List<QueryInspectionNoticeResp>> queryInspectionNoticeXML(QueryInspectionNoticeReq request) {
        log.info("=queryInspectionNotice-入参=>>>" + request.toString() + "=====");
        String serviceName = PlatFormServiceEnum.LabRequestGetCollectNote.getServiceName();
        String msgType = PlatFormServiceEnum.LabRequestGetCollectNote.getServiceCode();
        BaseResponse<List<QueryInspectionNoticeResp>> baseResponse = new BaseResponse();
        List<QueryInspectionNoticeNewResp> resps = new ArrayList<>();
        QueryInspectionExtraFeeXmlNewReq xmlRequest = this.transFormReq(request);
        try {
            HisXmlRequest<QueryInspectionExtraFeeXmlNewReq> req = new HisXmlRequest<>();
            req.setHeader(HisXmlHeader.Builder.custom()
                    .organization(request.getOrganizationId())
                    .sender("GOL")
                    .serviceType(Constants.SERVICE_TYPE_SERVICE)
                    .msgType(msgType)
                    .build());
            req.setBody(xmlRequest);
            LabRequestGetCollectNoteResponse.MsgBody.Data data = ServiceController.instance().singleWork(serviceName, request.getOrganizationId(), req, LabRequestGetCollectNoteResponse.MsgBody.Data.class);
            if (CommonUtils.isNotEmpty(data) && CommonUtils.isNotEmpty(data.getDatalists())) {
                resps = data.getDatalists().getDatalist();
                List<QueryInspectionNoticeResp> list = this.transFormResqD7(resps);
                baseResponse.setData(list);
            } else {
                baseResponse = BaseRespUtil.setResultError("获取申请单注意事项失败");
            }
        } catch (Exception e) {
            baseResponse = BaseRespUtil.setResultError("请求" + serviceName + "接口异常");
            return baseResponse;
        }
        return baseResponse;
    }


    public static void main(String[] args) {
//        String Msgheader = "<MsgHeader><Sender>HIS</Sender><MsgType>ODS_1001</MsgType><MsgVersion>3.0</MsgVersion></MsgHeader>";
//        QueryInspectionItemDtailNewReq req = new QueryInspectionItemDtailNewReq();
//        req.setVisitOrganization("330102001");
//        req.setItemCode("");
//        //转化为xml
//        String xml =  JAXBUtils.object2Xml(QueryInspectionItemDtailNewReq.class,req);
//        System.out.println("xml======   "+xml);
//        //请求
//        BaseResponse result = null;
//        try {
//             result =  CheckAppointmentUtil.postFromPlatform("http://10.8.3.125:8070/labPlatInterface/appServlet","LabRequestQuerySampletype",Msgheader,xml);
//        } catch (XMLStreamException e) {
//            e.printStackTrace();
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
//       System.out.println(result);
//
//
//        String json = result.getData().toString();
//        SampleTypeNewResponse list =  JSON.parseObject(json, SampleTypeNewResponse.class);
//        System.out.println("最终答案"+list.getResponse().getDatalists().getDatalist().get(0).getSampleTypeCode());
//        QueryInspectionExtraFeeNewReq req = new QueryInspectionExtraFeeNewReq();
//        req.setVisitOrganization("330102001");
//        QueryInspectionExtraFeeNewReq.Itemlists itemlists = new QueryInspectionExtraFeeNewReq.Itemlists();
//        InspectionItemNew inspectionItemNew = new InspectionItemNew();
//        inspectionItemNew.setItemCount(new BigDecimal("0.1"));
//        inspectionItemNew.setSampleTypeName("11");
//        inspectionItemNew.setSampleTypeCode("11");
//        inspectionItemNew.setRequestId("11");
//        inspectionItemNew.setItemName("1");
//        inspectionItemNew.setItemCode("1");
//        List<InspectionItemNew> inspectionItemNews = new ArrayList<>();
//        inspectionItemNews.add(inspectionItemNew);
//        itemlists.setItemlist(inspectionItemNews);
//        req.setItemlists(itemlists);
////        //转化为xml
//
//                String xml =  JAXBUtils.object2Xml(QueryInspectionExtraFeeNewReq.class,req);
//    System.out.println(xml);
//        String json = "{\"DataLists\":{\"DataList\":[{\"ItemTypeCode\":1,\"ItemTypeName\":\"生化系列\",\"Items\":{\"Item\":[{\"ItemCode\":6709,\"ItemPrice\":2,\"IsEmergency\":0,\"ItemName\":\"白细胞计数(WBC)\",\"ItemCount\":1,\"SampleTypeCode\":0,\"SampleTypeName\":\"末段尿\",\"ComposeType\":0,\"InputCode\":\"BXBJS\"},{\"ItemCode\":2008,\"ItemPrice\":139.5,\"IsEmergency\":0,\"ItemName\":\"生化全套\",\"ItemCount\":1,\"SampleTypeCode\":\"Q\",\"SampleTypeName\":\"血清\",\"ComposeType\":1,\"InputCode\":\"SHQT\"},{\"ItemCode\":12466,\"ItemPrice\":98,\"IsEmergency\":0,\"ItemName\":\"常规项目\",\"ItemCount\":1,\"SampleTypeCode\":\"C\",\"SampleTypeName\":\"血液\",\"ComposeType\":1,\"InputCode\":\"CGXM\"}]}},{\"ItemTypeCode\":2,\"ItemTypeName\":\"免疫系列\",\"Items\":{\"Item\":[{\"ItemCode\":2009,\"ItemPrice\":189,\"IsEmergency\":0,\"ItemName\":\"甲肝+丙肝\",\"ItemCount\":1,\"SampleTypeCode\":\"Q\",\"SampleTypeName\":\"血清\",\"ComposeType\":1,\"InputCode\":\"JGBG\"},{\"ItemCode\":2010,\"ItemPrice\":470,\"IsEmergency\":0,\"ItemName\":\"单纯疱疹I+II\",\"ItemCount\":1,\"SampleTypeCode\":\"Q\",\"SampleTypeName\":\"血清\",\"ComposeType\":1,\"InputCode\":\"DCPZII\"}]}},{\"ItemTypeCode\":3,\"ItemTypeName\":\"临检系列\",\"Items\":{\"Item\":{\"ItemCode\":1242,\"ItemPrice\":320,\"IsEmergency\":0,\"ItemName\":\"血常规\",\"ItemCount\":1,\"SampleTypeCode\":\"C\",\"SampleTypeName\":\"血液\",\"ComposeType\":1,\"InputCode\":\"XCG\"}}},{\"ItemTypeCode\":4,\"ItemTypeName\":\"急诊项目\",\"Items\":\"\"},{\"ItemTypeCode\":5,\"ItemTypeName\":\"微生物\",\"Items\":{\"Item\":[{\"ItemCode\":1206,\"ItemPrice\":30,\"IsEmergency\":0,\"ItemName\":\"痰培养及鉴定\",\"ItemCount\":1,\"SampleTypeCode\":\"K\",\"SampleTypeName\":\"痰\",\"ComposeType\":0,\"InputCode\":\"ZJPYJJD\"},{\"ItemCode\":1235,\"ItemPrice\":38,\"IsEmergency\":0,\"ItemName\":\"结核检测\",\"ItemCount\":1,\"SampleTypeCode\":\"C\",\"SampleTypeName\":\"血液\",\"ComposeType\":1,\"InputCode\":\"JHJC\"},{\"ItemCode\":1236,\"ItemPrice\":\"\",\"IsEmergency\":0,\"ItemName\":\"血需氧+厌氧菌培养及鉴定\",\"ItemCount\":1,\"SampleTypeCode\":\"C\",\"SampleTypeName\":\"血液\",\"ComposeType\":2,\"InputCode\":\"XXYYYJ\"},{\"ItemCode\":1244,\"ItemPrice\":\"\",\"IsEmergency\":0,\"ItemName\":\"血液培养1\",\"ItemCount\":1,\"SampleTypeCode\":\"C\",\"SampleTypeName\":\"血液\",\"ComposeType\":2,\"InputCode\":\"XYPY1\"},{\"ItemCode\":1245,\"ItemPrice\":\"\",\"IsEmergency\":0,\"ItemName\":\"尿培养\",\"ItemCount\":1,\"SampleTypeCode\":\"C\",\"SampleTypeName\":\"血液\",\"ComposeType\":2,\"InputCode\":\"NPY\"},{\"ItemCode\":1246,\"ItemPrice\":125,\"IsEmergency\":0,\"ItemName\":\"血培养\",\"ItemCount\":1,\"SampleTypeCode\":\"C\",\"SampleTypeName\":\"血液\",\"ComposeType\":1,\"InputCode\":\"XPY\"},{\"ItemCode\":1247,\"ItemPrice\":25,\"IsEmergency\":0,\"ItemName\":\"血厌氧培养及鉴定\",\"ItemCount\":1,\"SampleTypeCode\":\"C\",\"SampleTypeName\":\"血液\",\"ComposeType\":1,\"InputCode\":\"XYYPYJ\"}]}}]},\"MsgHeader\":{\"Sender\":\"HIP\",\"Status\":true,\"ReturnCount\":5,\"MsgType\":\"ODS_2140\",\"MsgVersion\":3,\"Detail\":\"查询成功\",\"ErrCode\":\"\"}}";
//        LabRequestQueryItemsResponse list =  JSON.parseObject(json, LabRequestQueryItemsResponse.class);
//        System.out.println(list.getDatalists().toString());
//        String json2 = "[{\"ItemTypeCode\":1,\"ItemTypeName\":\"生化系列\",\"Items\":{\"Item\":[{\"ItemCode\":6709,\"ItemPrice\":2,\"IsEmergency\":0,\"ItemName\":\"白细胞计数(WBC)\",\"ItemCount\":1,\"SampleTypeCode\":0,\"SampleTypeName\":\"末段尿\",\"ComposeType\":0,\"InputCode\":\"BXBJS\"},{\"ItemCode\":2008,\"ItemPrice\":139.5,\"IsEmergency\":0,\"ItemName\":\"生化全套\",\"ItemCount\":1,\"SampleTypeCode\":\"Q\",\"SampleTypeName\":\"血清\",\"ComposeType\":1,\"InputCode\":\"SHQT\"},{\"ItemCode\":12466,\"ItemPrice\":98,\"IsEmergency\":0,\"ItemName\":\"常规项目\",\"ItemCount\":1,\"SampleTypeCode\":\"C\",\"SampleTypeName\":\"血液\",\"ComposeType\":1,\"InputCode\":\"CGXM\"}]}},{\"ItemTypeCode\":2,\"ItemTypeName\":\"免疫系列\",\"Items\":{\"Item\":[{\"ItemCode\":2009,\"ItemPrice\":189,\"IsEmergency\":0,\"ItemName\":\"甲肝+丙肝\",\"ItemCount\":1,\"SampleTypeCode\":\"Q\",\"SampleTypeName\":\"血清\",\"ComposeType\":1,\"InputCode\":\"JGBG\"},{\"ItemCode\":2010,\"ItemPrice\":470,\"IsEmergency\":0,\"ItemName\":\"单纯疱疹I+II\",\"ItemCount\":1,\"SampleTypeCode\":\"Q\",\"SampleTypeName\":\"血清\",\"ComposeType\":1,\"InputCode\":\"DCPZII\"}]}},{\"ItemTypeCode\":3,\"ItemTypeName\":\"临检系列\",\"Items\":{\"Item\":{\"ItemCode\":1242,\"ItemPrice\":320,\"IsEmergency\":0,\"ItemName\":\"血常规\",\"ItemCount\":1,\"SampleTypeCode\":\"C\",\"SampleTypeName\":\"血液\",\"ComposeType\":1,\"InputCode\":\"XCG\"}}},{\"ItemTypeCode\":4,\"ItemTypeName\":\"急诊项目\",\"Items\":\"\"},{\"ItemTypeCode\":5,\"ItemTypeName\":\"微生物\",\"Items\":{\"Item\":[{\"ItemCode\":1206,\"ItemPrice\":30,\"IsEmergency\":0,\"ItemName\":\"痰培养及鉴定\",\"ItemCount\":1,\"SampleTypeCode\":\"K\",\"SampleTypeName\":\"痰\",\"ComposeType\":0,\"InputCode\":\"ZJPYJJD\"},{\"ItemCode\":1235,\"ItemPrice\":38,\"IsEmergency\":0,\"ItemName\":\"结核检测\",\"ItemCount\":1,\"SampleTypeCode\":\"C\",\"SampleTypeName\":\"血液\",\"ComposeType\":1,\"InputCode\":\"JHJC\"},{\"ItemCode\":1236,\"ItemPrice\":\"\",\"IsEmergency\":0,\"ItemName\":\"血需氧+厌氧菌培养及鉴定\",\"ItemCount\":1,\"SampleTypeCode\":\"C\",\"SampleTypeName\":\"血液\",\"ComposeType\":2,\"InputCode\":\"XXYYYJ\"},{\"ItemCode\":1244,\"ItemPrice\":\"\",\"IsEmergency\":0,\"ItemName\":\"血液培养1\",\"ItemCount\":1,\"SampleTypeCode\":\"C\",\"SampleTypeName\":\"血液\",\"ComposeType\":2,\"InputCode\":\"XYPY1\"},{\"ItemCode\":1245,\"ItemPrice\":\"\",\"IsEmergency\":0,\"ItemName\":\"尿培养\",\"ItemCount\":1,\"SampleTypeCode\":\"C\",\"SampleTypeName\":\"血液\",\"ComposeType\":2,\"InputCode\":\"NPY\"},{\"ItemCode\":1246,\"ItemPrice\":125,\"IsEmergency\":0,\"ItemName\":\"血培养\",\"ItemCount\":1,\"SampleTypeCode\":\"C\",\"SampleTypeName\":\"血液\",\"ComposeType\":1,\"InputCode\":\"XPY\"},{\"ItemCode\":1247,\"ItemPrice\":25,\"IsEmergency\":0,\"ItemName\":\"血厌氧培养及鉴定\",\"ItemCount\":1,\"SampleTypeCode\":\"C\",\"SampleTypeName\":\"血液\",\"ComposeType\":1,\"InputCode\":\"XYYPYJ\"}]}}]";
//        List<QueryInspectionItemListNewResp> resp = JSON.parseArray(json2, QueryInspectionItemListNewResp.class);
//        System.out.println(resp.get(0).getItems());
//        String json = "{\n" +
//                "    \"patientId\":\"2549\",\n" +
//                "    \"sourcePatientIdType\":\"1\",\n" +
//                "    \"authorOrganization\":\"1\",\n" +
//                "    \"patientName\":\"陈默默\",\n" +
//                "    \"sex\":\"1\",\n" +
//                "    \"birthday\":\"2004-06-12 00:00:00\",\n" +
//                "    \"cardType\":\"2\",\n" +
//                "    \"cardNumber\":\"460035200406127637\",\n" +
//                "    \"telephone\":\"\",\n" +
//                "    \"address\":\"\",\n" +
//                "    \n" +
//                "    \"patientHospitalNumber\":\"\",\n" +
//                "    \"organizationId\":\"1\",\n" +
//                "    \"source\":\"1\",\n" +
//                "    \"patientMedicalCardType\":\"2\",\n" +
//                "    \"patientMedicalCardNumber\":\"1908000784\",\n" +
//                "    \"inHospitalRecordCode\":\"1477\",\n" +
//                "    \"PatientProperties\":\"1000\",\n" +
//                "    \"onlineEmergencyNumber\":\"\",\n" +
//                "    \"registeredSerialNo\":\"\",\n" +
//                "    \"applicationlist\":{\n" +
//                "        \"applicationNo\":\"1062\",\n" +
//                "        \"isNeonatus\":\"0\",\n" +
//                "        \"age\":16,\n" +
//                "        \"inpatientWardId\":\"\",\n" +
//                "        \"inpatientWardName\":\"\",\n" +
//                "        \"bedNumber\":\"\",\n" +
//                "        \"isEmergency\":\"0\",\n" +
//                "        \"applyTime\":\"2020-09-22 11:05:18\",\n" +
//                "        \"effectiveTimeLow\":\"\",\n" +
//                "        \"effectiveTimeHigh\":\"\",\n" +
//                "        \"applyDoctorId\":\"2000004\",\n" +
//                "        \"applyDoctorName\":\"测试\",\n" +
//                "        \"applyDepartmentId\":\"1021\",\n" +
//                "        \"applyDepartmentName\":\"检验科\",\n" +
//                "        \"departmentId\":\"\",\n" +
//                "        \"departmentName\":\"\",\n" +
//                "        \"requestCheckerId\":\"\",\n" +
//                "        \"requestCheckerName\":\"\",\n" +
//                "        \"requestCheckTime\":\"\",\n" +
//                "        \"requestStatus\":2,\n" +
//                "        \"diagnosisReqList\":[\n" +
//                "            {\n" +
//                "                \"diseasesId\":\"\",\n" +
//                "                \"diseasesCode\":\"\",\n" +
//                "                \"diagnosisType\":\"1\",\n" +
//                "                \"diseasesName\":\"感冒\"\n" +
//                "            },\n" +
//                "            {\n" +
//                "                \"diseasesId\":\"\",\n" +
//                "                \"diseasesCode\":\"\",\n" +
//                "                \"diagnosisType\":\"2\",\n" +
//                "                \"diseasesName\":\"发烧\"\n" +
//                "            }\n" +
//                "        ],\n" +
//                "        \"inspectionItemDetailList\":[\n" +
//                "            {\n" +
//                "                \"expenseId\":\"4300\",\n" +
//                "                \"inspectionItemId\":\"1242\",\n" +
//                "                \"inspectionItemName\":\"血常规\",\n" +
//                "                \"specimenTypeId\":\"C\",\n" +
//                "                \"specimenTypeName\":\"血液\",\n" +
//                "                \"number\":\"1\",\n" +
//                "                \"price\":\"15\",\n" +
//                "                \"ItemCost\":\"15\",\n" +
//                "                \"feeStatus\":\"0\",\n" +
//                "                \"isFree\":\"0\",\n" +
//                "                \"executeDepartmentId\":\"3087\",\n" +
//                "                \"executeDepartmentName\":\"临检室\",\n" +
//                "                \"feeType\":\"1\",\n" +
//                "                \"itemList\":[\n" +
//                "                    {\n" +
//                "                        \"inspectionItemDetailId\":\"6\",\n" +
//                "                        \"inspectionItemDetailName\":\"25羟基维生素D测定-色谱法（艾迪康）\",\n" +
//                "                        \"jlxh\":\"6422\",\n" +
//                "                        \"itemId\":\"12394\",\n" +
//                "                        \"itemName\":\"25羟基维生素D测定-色谱法（艾迪康）\",\n" +
//                "                        \"number\":\"1\",\n" +
//                "                        \"price\":\"170\"\n" +
//                "                    },\n" +
//                "                    {\n" +
//                "                        \"inspectionItemDetailId\":\"24\",\n" +
//                "                        \"inspectionItemDetailName\":\"EB病毒核酸定量(艾迪康）\",\n" +
//                "                        \"jlxh\":\"6423\",\n" +
//                "                        \"itemId\":\"12391\",\n" +
//                "                        \"itemName\":\"EB病毒核酸定量(艾迪康）\",\n" +
//                "                        \"number\":\"1\",\n" +
//                "                        \"price\":\"150\"\n" +
//                "                    }\n" +
//                "                ]\n" +
//                "            }\n" +
//                "        ]\n" +
//                "    }\n" +
//                "}";
//
//        SaveInspectionInfoNewReq saveInspectionInfoReq =   JSONObject.parseObject(json,SaveInspectionInfoNewReq.class);
//        //转化为xml
//        String xml =  JAXBUtils.object2Xml(SaveInspectionInfoNewReq.class,saveInspectionInfoReq);
//        System.out.println(xml);


        String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><BSXml><MsgHeader><Sender>HIP</Sender><MsgType>ODS_2140</MsgType><MsgVersion>3.0</MsgVersion><Status>true</Status><ErrCode></ErrCode><Detail>查询成功</Detail><ReturnCount>1</ReturnCount></MsgHeader><Response><VisitOrganization>1</VisitOrganization><VisitOrganizationName>南滨街道卫生院</VisitOrganizationName><SourcePatientId>2549</SourcePatientId><Name>陈默默</Name><Sex>1</Sex><IdCardCode>2</IdCardCode><IdCard>460035200406127637</IdCard><MedicalCardType>2</MedicalCardType><MedicalCardId>1908000784</MedicalCardId><VisitId>1477</VisitId><Dept>1022</Dept><DeptName>内科</DeptName><RequestDoctor>2000004</RequestDoctor><RequestDoctorName>测试</RequestDoctorName><RequestDept>1021</RequestDept><RequestDeptName>检验科</RequestDeptName><LabRequest><RequestId>1062</RequestId><RequestStatus>2</RequestStatus><IsEmergency>0</IsEmergency><Items><Item><AdviceExpenseId>4300</AdviceExpenseId><ItemCode>1242</ItemCode><ItemName>血常规</ItemName><SampleTypeCode>C</SampleTypeCode><SampleTypeName>血液</SampleTypeName><ItemPrice>15</ItemPrice><ItemCount>1</ItemCount><ItemCost>15</ItemCost><FeeStatus>0</FeeStatus><CostFreeSign>0</CostFreeSign><RequestNote></RequestNote><InvoiceNo></InvoiceNo><ExamExecuteDept>3087</ExamExecuteDept><ExamExecuteDeptName>临检室</ExamExecuteDeptName><ExamMethodCode></ExamMethodCode><ExamMethodName></ExamMethodName><FeeType>0</FeeType><Childitems><Childitem><ChildItemCode>6</ChildItemCode><ChildItemName>25羟基维生素D测定-色谱法（艾迪康）</ChildItemName><AdviceExpenseDetailId>6422</AdviceExpenseDetailId><CostId>12394</CostId><CostName>25羟基维生素D测定-色谱法（艾迪康）</CostName><CostNumber>1</CostNumber><CostPrice>170</CostPrice><CostUnit></CostUnit><DetailCost>170.0</DetailCost></Childitem><Childitem><ChildItemCode>24</ChildItemCode><ChildItemName>EB病毒核酸定量(艾迪康）</ChildItemName><AdviceExpenseDetailId>6423</AdviceExpenseDetailId><CostId>12391</CostId><CostName>EB病毒核酸定量(艾迪康）</CostName><CostNumber>1</CostNumber><CostPrice>150</CostPrice><CostUnit></CostUnit><DetailCost>150.0</DetailCost></Childitem></Childitems></Item></Items></LabRequest></Response></BSXml>";

        LabRequestSubmitResponse json12 = JAXBUtils.xml2Object(xml, LabRequestSubmitResponse.class);
        System.out.println(json12);
    }
}

